home *** CD-ROM | disk | FTP | other *** search
- { cursor.pas -- Display built-in and custom cursors }
-
- program Cursor;
-
- {$R cursor.res}
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- id_Cursor = 200; { Custom cursor resource ID }
-
- cm_Arrow = 101; { Menu command values }
- cm_Cross = 102;
- cm_IBeam = 103;
- cm_Icon = 104;
- cm_Size = 105;
- cm_SizeNESW = 106;
- cm_SizeNS = 107;
- cm_SizeNWSE = 108;
- cm_SizeWE = 109;
- cm_UpArrow = 110;
- cm_Wait = 111;
-
- firstCommand = cm_Arrow; { First and last command constants }
- lastCommand = cm_Wait;
-
- type
-
- CursorApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PCursorWindow = ^CursorWindow;
- CursorWindow = object(TWindow)
- ButtonDown: Boolean;
- CurCustom, CurCurrent: HCursor;
- CurCommand: Word;
- CursorHandles: array[firstCommand .. lastCommand] of HCursor;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure WMCommand(var Msg: TMessage);
- virtual wm_First + wm_Command;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- procedure WMLButtonUp(var Msg: TMessage);
- virtual wm_First + wm_LButtonUp;
- end;
-
-
- {- Toggle a checkmarked menu item on or off }
- procedure ToggleCheck(Menu: HMenu; MenuItemID: Word);
- var
- MAttr, WCheck: Word;
- begin
- MAttr := GetMenuState(Menu, MenuItemID, mf_ByCommand);
- if (MAttr and mf_Checked) = mf_Checked then
- WCheck := mf_ByCommand or mf_Unchecked
- else
- WCheck := mf_ByCommand or mf_Checked;
- CheckMenuItem(Menu, MenuItemID, WCheck)
- end;
-
-
- { CursorApplication }
-
- {- Initialize CursorApplication object's window }
- procedure CursorApplication.InitMainWindow;
- begin
- MainWindow := New(PCursorWindow, Init(nil,
- 'Click left mouse button to use selected cursor'))
- end;
-
-
- { CursorWindow }
-
- {- Construct CursorWindow object }
- constructor CursorWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- var
- I: Integer;
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- ButtonDown := false;
- CurCustom := LoadCursor(HInstance, PChar(id_Cursor));
- CursorHandles[cm_Arrow] := LoadCursor(0, idc_Arrow);
- CursorHandles[cm_IBeam] := LoadCursor(0, idc_IBeam);
- CursorHandles[cm_Wait] := LoadCursor(0, idc_Wait);
- CursorHandles[cm_Cross] := LoadCursor(0, idc_Cross);
- CursorHandles[cm_UPArrow] := LoadCursor(0, idc_UPArrow);
- CursorHandles[cm_Size] := LoadCursor(0, idc_Size);
- CursorHandles[cm_Icon] := LoadCursor(0, idc_Icon);
- CursorHandles[cm_SizeNWSE] := LoadCursor(0, idc_SizeNWSE);
- CursorHandles[cm_SizeNESW] := LoadCursor(0, idc_SizeNESW);
- CursorHandles[cm_SizeWE] := LoadCursor(0, idc_SizeWE);
- CursorHandles[cm_SizeNS] := LoadCursor(0, idc_SizeNS);
- CurCurrent := CursorHandles[cm_Arrow];
- CurCommand := cm_Arrow;
- ToggleCheck(Attr.Menu, CurCommand)
- end;
-
- {- Modify window class to use custom cursor }
- procedure CursorWindow.GetWindowClass(var AWndClass: TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.HCursor := CurCustom; (*LoadCursor(0, idc_UpArrow)*)
- end;
-
- {- Intercept wm_Command messages }
- procedure CursorWindow.WMCommand(var Msg: TMessage);
- begin
- with Msg do
- case WParam of
- firstCommand .. lastCommand:
- begin
- CurCurrent := CursorHandles[WParam];
- ToggleCheck(Attr.Menu, CurCommand);
- ToggleCheck(Attr.Menu, WParam);
- CurCommand := WParam
- end
- else
- TWindow.WMCommand(Msg)
- end
- end;
-
- {- Respond to left mouse button down events }
- procedure CursorWindow.WMLButtonDown(var Msg: TMessage);
- begin
- if not ButtonDown then with Msg do
- begin
- ButtonDown := true;
- SetCursor(CurCurrent);
- SetCapture(HWindow)
- end
- end;
-
- {- Respond to left mouse button up events }
- procedure CursorWindow.WMLButtonUp(var Msg: TMessage);
- begin
- if ButtonDown then with Msg do
- begin
- ButtonDown := false;
- SetCursor(CurCustom);
- ReleaseCapture
- end
- end;
-
- var
-
- CursorApp: CursorApplication;
-
- begin
- CursorApp.Init('CursorApp');
- CursorApp.Run;
- CursorApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 3/09/1991
- ---------------------------------------------------------------}
-